//
//  CustomUIViewController.m
//  UI04_Switch_Slider_SegmentedCintrol
//
//  Created by aaaaaa on 16/6/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomUIViewController.h"
#import "CustomUISwitch.h"
#import "CustomUISlider.h"
#import "CustomUIPageControl.h"
#import "CustomerUIButton.h"
#import "CustomUISegmentControl.h"

@interface CustomUIViewController ()

@end

@implementation CustomUIViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createUISwitch];
    [self createUISlider];
    [self createPageControl];
    [self createSegmentControl];
    [self createButton];
}



#pragma mark - UISwitch
- (void)createUISwitch{
    //设置UISwitch对象的size，对它没有影响，系统规定的大小不可变
    CustomUISwitch *customSwitch = [[CustomUISwitch alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
//    customSwitch.backgroundColor = [UIColor redColor];
    [self.view addSubview:customSwitch];
    [customSwitch release];
    
    [customSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
}

- (void)switchAction:(CustomUISwitch *)customSwitch{
    //当状态为on时设置背景色为灰色  状态为off是设置背景色为白色
    if (customSwitch.on) {
        self.view.backgroundColor = [UIColor grayColor];
    } else {
        self.view.backgroundColor = [UIColor whiteColor];
    }
}

#pragma mark - UISlider
- (void)createUISlider{
    //UISlider 控件的width影响了长短，height影响了触摸范围，height为0的时候，控件将不能滑动，height需要给一个合适的值
    CustomUISlider *customSlider = [[CustomUISlider alloc] initWithFrame:CGRectMake(100, 200, 200, 100)];
    [self.view addSubview:customSlider];
    [customSlider release];
    
    [customSlider addTarget:self action:@selector(slidetAction:) forControlEvents:UIControlEventValueChanged];
}

- (void)slidetAction:(CustomUISlider *)customSlider{
    self.view.alpha = 1 - customSlider.value / 100.0;
}

#pragma mark - UIPageControl
- (void)createPageControl{
    CustomUIPageControl *pageControl = [[CustomUIPageControl alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
    pageControl.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:pageControl];
    [pageControl release];
    [pageControl addTarget:self action:@selector(pageControlAction:) forControlEvents:UIControlEventValueChanged];
}

- (void)pageControlAction:(CustomUIPageControl *)pageControl{
    switch (pageControl.currentPage) {
        case 0:
            NSLog(@"第%ld个点", pageControl.currentPage + 1);
            break;
        case 1:
            NSLog(@"第%ld个点", pageControl.currentPage + 1);
            break;
        case 2:
            NSLog(@"第%ld个点", pageControl.currentPage + 1);
            break;
        case 3:
            NSLog(@"第%ld个点", pageControl.currentPage + 1);
            break;
        case 4:
            NSLog(@"第%ld个点", pageControl.currentPage + 1);
            break;
            
        default:
            break;
    }
}



- (void)createSegmentControl{
    
    
    CustomUISegmentControl *customSegment = [[CustomUISegmentControl alloc] initWithItems:@[@"橘黄", @"紫色", @"棕色"]];
    customSegment.frame = CGRectMake(50, 500, 200, 50);
    [self.view addSubview:customSegment];
    [customSegment release];
    
    [customSegment addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
    
}


- (void)segmentedAction:(CustomUISegmentControl *)seg{
    switch (seg.selectedSegmentIndex) {
        case 0:
            self.view.backgroundColor = [UIColor orangeColor];
            break;
        case 1:
            self.view.backgroundColor = [UIColor purpleColor];
            break;
        case 2:
            self.view.backgroundColor = [UIColor brownColor];
            break;
        default:
            break;
    }
}

- (void)createButton {
    CustomerUIButton *button = [CustomerUIButton button];
    button.frame = CGRectMake(100, 200, 50, 50);
    [self.view addSubview:button];
    
    //    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
}
//
//- (void)buttonAction:(CustomerUIButton *)button{
//    button.selected = !button.selected;
//    if (button.selected) {
//
//        NSString *path = [[NSBundle mainBundle] pathForResource:@"checked" ofType:@"png"];
//        UIImage *image = [UIImage imageWithContentsOfFile:path];
//        [button setImage:image forState:UIControlStateNormal];
//
//    } else{
//        NSString *path = [[NSBundle mainBundle] pathForResource:@"check" ofType:@"png"];
//        UIImage *image = [UIImage imageWithContentsOfFile:path];
//        [button setImage:image forState:UIControlStateNormal];
//        }
//}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
